1. Field of the Invention
The present invention relates to a compiling apparatus for improving the performance of and optimizing compiler.
Recent computers are required to operate at high speed. To improve the operation speed, processors that simultaneously execute a plurality of instructions and machines that carry out vector operations have been developed. These situations have raised the needs of optimizing compilers.
Compilers translate a source program written in a programming language such as C, FORTRAN, and COBOL into another language such as assembler. The "optimization" of compiling means to translate a source program in such a way as to improve the execution speed of a translated program and reduce a memory area required by the translated program, without changing the meaning of the source program.
Generally, compilers optimize a source program through intermediate representations, which are synonymous with intermediate languages, intermediate texts, or internal representations. The intermediate representations are independent of a computer or a work station that executes a translated program. Some of the intermediate representations are eliminated, moved, and integrated through optimization, to thereby provide optimized object codes. The selection of intermediate representations, therefore, affects the performance and speed of optimization. If the types and contents of the intermediate representations are fixed according to a specific stand point, the optimization will frequently be unsuccessful because there are various kinds of optimization and final objects that will not fit the fixed intermediate representations.
The present invention relates to optimizing a compiler that translates a programming language into an assembler language or a machine language.
2. Description of the Related Art
Optimization means deleting, moving, and integrating intermediate representations, to provide high-speed small-sized efficient object code.
The intermediate representations must be independent of languages and machines when achieving the optimization and providing common code generators and standardized parts. The intermediate representations are explained in, for example, a reference 1 "Compiler: principles, techniques, and tools" by A.V. Aho et al, Science, and a reference 2 "A way of thinking of intermediate languages," Interface, March 1989, pp 211 to 219.
Conventional optimization involves a front end, an optimizing section, and a code output section.
The front end provides intermediate representations according to a source program. The intermediate representations are optimized by the optimizing section, to improve the execution speed of the program and reduce the size of the program. The optimized result is supplied to the code output section, which provides code based on a machine-dependent programming language such as a machine language dedicated to a target machine.
The intermediate representations optimized by the optimizing section are independent of languages and machines.
There are compilers that change the structure of intermediate representations during optimization. Such compilers are explained in a reference 3 "Optimizing compilers for SPARC" by S. S. Muchnick, Sun Technology, 1988, and in a reference 4 "A global optimizer for Sun FORTRAN, C and Pascal" by Ghodssi, Vida, S. S. Muchnick, and Alex Wu, USENIX Conference, 1986. These compilers mainly substitute existing processes for partial processes during compilation and change the physical memory map of data structure of intermediate representations.
Japanese Unexamined Patent Publication No. 2-81137 discloses the structure of an optimizing compiler. Objects of this disclosure are to (1) efficiently optimize a source program, (2) efficiently collect optimization data, (3) quickly find optimization functions to achieve, (4) eliminate side effect elements of the source program, and (5) clear side effects of the source program. This prior art initially changes an intermediate language (intermediate representations) and optimizes the changed one.
As explained above, the conventional compilers design and prepare an optimizing section according to fixed intermediate representations, causing the following problems:
(1) Machine instructions and intermediate representations do not always have a one-to-one relationship. For example, if an instruction scheduling function that determines the positions of different machine instructions is compiled under a single intermediate representation, the intermediate representation will be unable to optimize the different machine instructions involved in the function. PA1 (2) Even if all intermediate representations provided by a front end are related to machine instructions, respectively, there will still be the following problems: PA1 (3) Each optimization function is applied only to a predetermined intermediate representation. This puts limits on the front end and on optimization.
(a) The intermediate representations provided by the front end must be independent of a target machine. If not so, different intermediate representations must be prepared for different target machines, and the front end must be renewed whenever a compiler is prepared. PA2 (b) Relating instructions and intermediate representations to each other in a one-to-one relationship in the front end increases the number of the intermediate representations, to thereby complicate optimization and elongate an optimization time. For example, if a target machine is designed for 32-bit instructions and if it is impossible to load or store a 32-bit address at one time, two instructions are combined to substitute for a load/store instruction to address 32 bits. If the front end relates the two instructions to different intermediate representations, it is necessary to recognize during optimization that the two specific instructions serve as the single load/store instruction. This is not as simple as recognizing a single load or store instruction and complicates the optimization.
The intermediate representation changing techniques disclosed in the references 3 and 4 completely change the physical data structures of intermediate representations. Accordingly, these techniques hardly standardize optimization functions.